<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>添加用户</title>
<link href="__PUBLIC__/admin/css/xc.min.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/admin/css/xc.admin.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/lib/iconfont/iconfont.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__PUBLIC__/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.js"></script> 
<script type="text/javascript" src="__PUBLIC__/admin/js/xc.admin.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/js/common-1.0.js"></script>
<script type="text/javascript" src="__PUBLIC__/lib/layer/layer.js"></script>
</head>
<body>
<div class="pd-20">
  <form action="" method="post" class="form form-horizontal" id="myform">
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>直推人：</label>
      <div class="formControls col-6">
        <input type="text" id="pid" class="input-text" onBlur="getUname('pid')" placeholder="请输入直推会员ID或手机号">
      </div>
      <input type="hidden" id="pidval" name="pidval">
      <div class="col-3 pt-3" id="pidtishi"></div>
    </div>
<!--    <div class="row cl">-->
<!--      <label class="form-label col-3"><span class="c-red">*</span>节点人：</label>-->
<!--      <div class="formControls col-8">-->
<!--        <input type="text" id="lid" name="lid" class="input-text" placeholder="请输入节点人">-->
<!--      </div>-->
<!--      <div class="col-4"> </div>-->
<!--    </div>-->
<!--		<div class="row cl">-->
<!--			<label class="form-label col-3"><span class="c-red">*</span>选择左右区：</label>-->
<!--			<div class="formControls col-8">-->
<!--				<input type="text" id="place" name="place" class="input-text" placeholder="左区为1 右区为2">-->
<!--			</div>-->
<!--			<div class="col-4"> </div>-->
<!--		</div>-->
		<div class="row cl">
			<label class="form-label col-3"><span class="c-red">*</span>会员名：</label>
			<div class="formControls col-8">
				<input type="text" id="uname" name="uname" class="input-text" placeholder="请输入会员真实姓名">
			</div>
			<div class="col-4"> </div>
		</div>
    <div class="row cl">
      <label class="form-label col-3"><span class="c-red">*</span>手机号：</label>
      <div class="formControls col-8">
        <input type="text" id="phone" name="phone" class="input-text" placeholder="请输入您常用的手机号">
      </div>
      <div class="col-4"> </div>
    </div>
    <input type="hidden" id="type" name="type" class="input-text" value="1">
    <div class="row cl">
      <div class="col-9 col-offset-3">
        <button type="button" id="sub" name="sub" class="btn btn-primary radius" onClick="checkSubmit()"><i class='Hui-iconfont'>&#xe632;</i> 保存</button>
        <button class="btn btn-default radius" type="button" onClick="layer_close();"><i class='Hui-iconfont'>&#xe66b;</i> 取消</button>
      </div>
    </div>
  </form>
</div>
<script type="text/javascript">
//按回车件触发提交
document.onkeydown=function(event){
	var e = event || window.event || arguments.callee.caller.arguments[0];
	if(e && e.keyCode==13){ // enter 键
		checkSubmit();
	}
};
function getUname(id){
    var uid = $.trim($("#"+id).val());
    // alert(uid);return false;
    if(uid == ''){
        $("#"+id+"tishi").html('不能为空!').css("color","red");
        return false;
    }
    if(uid.length>8){
        if(!checkMobile(uid)){
            $("#"+id+"tishi").html('手机号格式不正确!').css("color","red");
            return false;
        }
    }else{
        if(!checkUserId(uid)){
            $("#"+id+"tishi").html('会员ID格式不正确!').css("color","red");
            return false;
        }
    }
    //alert(uid);
    $.ajax({
        type : 'post',
        url : '/Hoteladmin/Login/verUserName',
        data : {id:uid},
        dataType : 'json',
        success : function(res){
            if(res.status == 1){
                $("#"+id+"val").val(res.uid);
                $("#"+id+"tishi").html(res.msg).css("color","green");
            }else{
                $("#"+id+"tishi").html(res.msg).css("color","red");
            }
        }
    })
}
//提交数据
function checkSubmit()
{
	var uid = $.trim($('#pidval').val());
	var una = $.trim($('#uname').val());
	var pho = $.trim($('#phone').val());
	var lid = $.trim($('#lid').val());
	var place = $.trim($('#place').val());
	if(uid == ''){
		layer.msg('直推会员不能为空', {icon: 2});
		return false;
	}
// 	if(lid == ''){
// 	layer.msg('节点人不能为空', {icon: 2});
// 	return false;
// }if(place == ''){
// 	layer.msg('左右区不能为空', {icon: 2});
// 	return false;
// }
	if(una == ''){
		layer.msg('会员真实姓名不能为空!', {icon: 2});
		return false;
	}if(una.length>4){
		layer.msg('真实姓名不能超过4个字符!', {icon: 2});
		return false;
	}if(pho == ''){
		layer.msg('会员手机不能为空!', {icon: 2});
		return false;
	}if(!checkMobile(pho)){
		layer.msg('手机号码格式不正确!', {icon: 2});
		return false;
	}
	$.ajax({
		type : 'post',
		url : '__MODULE__/User/userAdd',
		data : $("#myform").serialize(),
		dataType : 'json',
		success : function(res){
			if(res.status == 1){
				layer.msg(res.msg,{icon:1,time:2000},function(){
					// 先获取窗口索引，才能关闭窗口  
					var index = parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);
				});
				parent.call_back_fun('success');
			}else{
				layer.msg(res.msg, {icon: 2});
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			layer.alert('网络失败，请刷新页面后重试',{icon:2});
		}
	})
}
</script>
</body>
</html>